package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import po.Employees;
import service.EmployeeService;
import utils.JsonResult;

import java.util.List;

@Controller
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("/getAllEmp")
    @ResponseBody
    public JsonResult getAllEmployees() {
        JsonResult result = new JsonResult();
        List<Employees> employees = null;
        String msg = null;
        int code = 0;
        try {
            msg = "ok";
            code = 200;
            employees = employeeService.selectAllEmployees();
        } catch (Exception e) {
            msg = e.getMessage();
            code = 500;
            e.printStackTrace();
        }
        result.setMsg(msg);
        result.setStatus(code);
        result.setData(employees);
        return result;
    }

}
